home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Windows News 2010 Summer - Disc 1
/
WN_Ete2010_CD1.iso
/
Onglet5
/
Weezo
/
Weezo setup.exe
/
{code_appDir}
/
www
/
includes
/
resourceConfigFunctions.php
< prev
next >
Wrap
PHP Script
|
2010-05-19
|
78KB
|
1,933 lines
<?php
/**
* Resource configuration common functions
*
* This script is either included by accounts.php (if accessed from a browser) or directly called by embeded browser of application
*
* PHP version 5
*
* LICENSE: This source file is subject to version 3.0 of the PHP license
* that is available through the world-wide-web at the following URI:
* http://www.php.net/license/3_0.txt. If you did not receive a copy of
* the PHP License and are unable to obtain it through the web, please
* send a note to license@php.net so we can mail you a copy immediately.
*
* @category NA
* @package NA
* @author Nicolas Bruley / Peer 2 World <contact@weezo.net>
* @copyright 2005-2009 Nicolas Bruley / Peer 2 World
* @license http://www.php.net/license/3_0.txt PHP License 3.0
* @version CVS: $Id:$
* @link http://www.weezo.net
* @since File available since Release 1.0.0
*/
/*
***************************************************************************************************************************
* Wrappers
***************************************************************************************************************************
*/
/**
* @desc Set configuration rights
* Display error page if config not allowed
* @return boolean : true if user may only modifiy non-sensitive parameters, for this session only,
* or false if user has full-configuration rights
*
*/
function rcConfigRights($limitedConfigAllowed=false){
global $includedByResourceConfig;
// If included by resourceConfig.php script: access control has already beed done (double check anyway)
if(isset($includedByResourceConfig) && (cfIsInApp() || (cfUGetVar('administrator') && ($_SERVER['REMOTE_ADDR']==='127.0.0.1' || cfGGetVar('remoteAdministrationAuthorized'))))) return false;
// If limited config allowed, initialize limited configuration environment
if($limitedConfigAllowed) {
rcInitLimitedConfig();
return true;
}
// Else forbid access and log
cfLog('administration : unauthorized access attempt by '.$_SERVER['REMOTE_ADDR'], LOG_INF);
require_once(INCLUDE_DIR.'outputFunctions.php');
outDisplayErrorPage(cfcaption('errorRemoteAdministrationNotAuthorized')); // If no access right, display error page and exit
}
/**
* @desc Return resource name (caption)
*
* @param string $type
* @param string $subType
* @param array $rData: optional: resource definition
* @return string UTF8 encoded caption
*/
function rcResourceCaptionUTF8($type, $subType ,&$rData=null){
if(cfCaptionExist($type.'_'.$subType.'-name')) return cfCaption($type.'_'.$subType.'-name');
if(cfCaptionExist(strtolower($type.'_'.$subType.'-name'))) return cfCaption(strtolower($type.'_'.$subType.'-name'));
if($rData===null) $rData=cfMGetVar('weezoResourceDefinition'.strtolower($type).strtolower($subType));
if(isset($rData['describer'][cfGGetVar('language')]['name'])) return $rData['describer'][cfGGetVar('language')]['name'];
return cfUTF8Encode($subType);
}
/**
* @desc Return resource description
*
* @param string $type
* @param string $subType
* @param array $rData: optional: resource definition
* @return string UTF8 encoded caption
*/
function rcResourceDescriptionUTF8($type, $subType ,&$rData=null){
if(cfCaptionExist($type.'_'.$subType.'-description')) return cfCaption($type.'_'.$subType.'-description');
if(cfCaptionExist(strtolower($type.'_'.$subType.'-description'))) return cfCaption(strtolower($type.'_'.$subType.'-description'));
if($rData===null) $rData=cfMGetVar('weezoResourceDefinition'.strtolower($type).strtolower($subType));
if(isset($rData['describer'][cfGGetVar('language')]['description'])) return $rData['describer'][cfGGetVar('language')]['description'];
return cfCaption('genNoDescription');
}
/**
* @return mixed array : parsed file (or false if file couldn't be opened)
* @param string $fileName : file name (not including path)
* @desc parse a user file
*/
function rcParseUserFile($fileName){
$file=cfAppDataDir().'/'.$fileName;
if(!file_exists($file)) return false;
return cfParse_ini_file($file,true);
}
/**
* @return mixed array : parsed file (or false if file couldn't be opened)
* @param string $fileName : file name (not including path)
* @desc parse a resource file
*/
function rcParseResourceFile($fileName){
$file=cfAppDataDir().'/'.$fileName;
if(!file_exists($file)) return false;
return cfParse_ini_file($file, true);
}
/**
* @return mixed array : parsed file (or false if file couldn't be opened)
* @desc parse the transfers file
*/
function rcParseTransfersFile(){
$file=cfAppDataDir().'/transfers.txt';
if(!file_exists($file)) return false;
return cfParse_ini_file($file,true);
}
/**
* @return mixed: filename if success, false if user file couldn't be written
* @param mixed array $params : complete user configuration
* @param string $fileName : file name (not including path). If not set, try to detect filename from $params
* @param bool $commit: true to update UI and to reload all users (should be used when a single user is updated)
* @desc Write .usr user configuration file, from $params array of parameters
*/
function rcWriteUserFile($params, $fileName='',$commit=true){
if(!$fileName){
if(isset($params['configFilename'])) $fileName=$params['configFilename'];
else {
cfLog('administration : error saving user file, filename not found', LOG_ER);
return false;
}
}
// Save file
if(!cfWriteIniFile($params,cfAppDataDir().'/'.$fileName,true)){
cfLog('administration : error saving '.$fileName.' user file', LOG_ER);
return false;
}
//cfServerSendCommand('refreshUser file="'.$fileName.'"');
cfLog('administration : '.$fileName.' user file modified by '.$_SERVER['REMOTE_ADDR'], LOG_DBG);
// Reload users into memory
require_once(INCLUDE_DIR.'initFunctions.php');
ifLoadUsers();
return $fileName;
}
/**
* @desc Update several user files
*
* @param array $users: array of user config array
*/
function rcWriteUserFiles($users){
if(!is_array($users) || count($users)==0) return ;
// Save to disk
$filenames=array();
foreach ($users as $userConfig) $filenames[]=rcWriteUserFile($userConfig,'',false);
// Update UI
$nb=0;
$command='refreshUsers';
foreach ($filenames as $filename) if($filename) $command.=' file'.($nb++).'="'.$filename.'"';
if($nb) cfServerSendCommand($command);
// Reload all users
ifLoadUsers();
}
/**
* @desc return an array id=>properties of users bound to resource
*
* @param string $filename: resource id OR resource config filename
* @return array
*/
function rcResourceGetUsers($filename){
$bound=array();
// If id passed, search matching filename
if(!strpos($filename,'.res')){
if(!($filename=cfArrayItem(cfMGetVar('weezoResourcesList'),$filename))) return array();
}
// Browse users
foreach (cfMGetVar('weezoUsers') as $id=>$user){
$i=0;
// Browse user's resources
while (isset($user['resource'.$i]['file'])) {
// If searched resource matches
if($user['resource'.$i]['file']==$filename){
$bound[$id]=$user;
break;
}
$i++;
}
}
return $bound;
}
/**
* @return boolean : true if success, false if user file couldn't be written
* @param mixed array $params : complete user configuration
* @param string $fileName : file name (not including path)
* @param string $forceCommitToApp: true to force application resource update
* @desc Write .res resource configuration file, from $params array of parameters
*/
function rcWriteResourceFile($params, $fileName=false, $forceCommitToApp=false){
global $resourceNameModified;
global $limitedConfig;
global $originalResourceData;
// Remove data directly linked to resource definition
unset($params['definition']);
// Check if config has been modified
if(isset($originalResourceData)){
$commit=false;
foreach ($params as $k=>$v){
if(!isset($originalResourceData[$k])){$commit=true;break;}
if(is_array($v)){
foreach ($v as $k2=>$v2){
if($originalResourceData[$v][$k2]!==$v2) {$commit=true;break 2;}
}
}
elseif ($v!==$originalResourceData[$k]){
if($k!=='path' || str_replace('*appDir*',cfAppDataRootDir(),$v)!==$originalResourceData[$k]){$commit=true;break;}
}
}
// Config not modified - exit
if(!$commit) return true;
}
if(!$fileName && isset($params['resourceFilename'])) $fileName=$params['resourceFilename'];
elseif(!$fileName && isset($params['resourceName'])) $fileName=$params['resourceName'].'.res';
// Limited configuration : apply changes to current resource data
if($limitedConfig) {
// Apply
foreach ($params as $key=>$value) if($value!=cfRGetVar($key)) cfRSetVar($key,$value);
//$_SESSION['res'][$_SESSION['activeResourceId']]=$params;
// Reload opener window and close this window
if(count($_POST)) echo '<script type="text/javascript">function onLoadFunc(){applyChanges()}</script>';
else
echo <<<EOT
<script type="text/javascript">
function onLoadFunc(){winMe.resizeInnerTo(545,dgi('limitedConfigFrame').offsetHeight+10,1)}
</script>
EOT;
return true;
}
// Normal config : commit new data to resource config file
$newResource=!file_exists(cfAppDataDir().'/'.$fileName);
if(!cfWriteIniFile($params,cfAppDataDir().'/'.$fileName,true)){
cfLog('administration : error saving '.$fileName.' resource file', LOG_ER);
return false;
}
// Update in-memory resource data
require_once(INCLUDE_DIR.'initFunctions.php');
ifLoadResource($fileName,$params);
if($forceCommitToApp || $newResource || isset($resourceNameModified)) {
// Update in application (still needed as filename modification in DB are done through app)
cfServerSendCommand('refreshResource file="'.$fileName.'" resourceNameModified="true"');
// Reset users-resources associations
if($newResource) {
require_once(INCLUDE_DIR.'initFunctions.php');
ifResetResourcesUsers(false,false);
}
}
cfLog('administration : '.$fileName.' configuration file modified by '.$_SERVER['REMOTE_ADDR'], LOG_DBG);
return true;
}
/**
* @desc Create a new resource
*
* @param string $type
* @param string $subType
* @param array $resourceData (optional): preset resource data
* @return string resource configuration filename
*/
function rcCreateResource($type,$subType,$resourceData=false){
// Clean $type & $subType
$type =str_replace('/','',str_replace('\\','',str_replace('..','',$type)));
$subType=str_replace('/','',str_replace('\\','',str_replace('..','',$subType)));
// Verify it's actually a resource
if(is_dir(cfAppDocRoot().'/res/'.$type.'/'.$subType)){
// Generate resource file
$rData=rcGetResourceDefinition($type,$subType);
$tmpResource=array();
if(is_array($resourceData)) $tmpResource=$resourceData;
if(!isset($tmpResource['name'])) $tmpResource['name']=cfUTF8Decode($rData['name']);
$tmpResource['type']=$type;
$tmpResource['subType']=$subType;
$tmpResource['id']=substr(sha1(rand().rand().rand()),0,10);
// Get default parameters if present
if(file_exists(cfAppDocRoot().'/res/'.$type.'/'.$subType.'/defaultConfig.php')){
$defaultConfig=cfParse_ini_file(cfAppDocRoot().'/res/'.$type.'/'.$subType.'/defaultConfig.php');
foreach ($defaultConfig as $key=>$value) if($key!='name' && $key!='type' && $key!='subType') $tmpResource[$key]=$value;
unset($defaultConfig);
}
// Write resource file
$nb=1;
while(file_exists(cfAppDataDir().'/'.$type.$subType.$nb.'.res')) $nb++;
rcWriteResourceFile($tmpResource,$type.$subType.$nb.'.res');
return $type.$subType.$nb.'.res';
}
return false;
}
/**
* @desc Add an asynchronous javascript or HTML insertion command
*
* @param string $xmlNode: xml node generated by cfAsyncXMLInnerHTMLbyId(), cfAsyncXMLJSaction()...
*/
function rcAddAsyncResponse($xmlNode){
if(!isset($_ENV['rcAsyncResponse'])) $_ENV['rcAsyncResponse']=$xmlNode;
else $_ENV['rcAsyncResponse'].=$xmlNode;
}
/**
* @desc : return path from server root of image located in resource directory
* @return : string : path
*
* @param string $fileName : name of image (without path)
*/
function rcResourceImage($fileName){
global $resourceData; return '/res/'.$resourceData['type'].'/'.$resourceData['subType'].'/'.$fileName;
}
/**
* @desc Copy $resourceData into $_SESSION['res'][0] so functions using cfRgetVar / cfRSetVar can be used by configuration scripts
*
*/
function rcCopyResourceDataToRVar(){
global $resourceData;
$_SESSION['activeResourceId']=0;
$_SESSION['res'][0]=$resourceData;
}
/**
* @desc Create resource data directory if needed
*
*/
function rcCreateResourceDataDir(){
global $resourceData;
global $fileName;
if($resourceData['resourceDataDirAccessAllowed']){
$subTypeDir = cfAppDataDir()."/res/".$resourceData['type'] ."/".$resourceData['subType'];if(!file_exists($subTypeDir)) @mkdir($subTypeDir);
$dataDir = cfAppDataDir()."/res/".$resourceData['type'] ."/".$resourceData['subType']."/". cfFileWithoutExtension($fileName);if(!file_exists($dataDir)) @mkdir($dataDir);
}
}
/**
* @desc set a PHP callback function that will be called on resource data change
* Callback function must have 2 parameters :
- string $dataName
- mixed $previousDataValue
*
* @param string $functionName
*/
function rcSetModifiedValuePHPFunction($functionName){
global $modifiedValuePHPFunction;
$modifiedValuePHPFunction=$functionName;
}
/**
* @desc Insert / update key/value pair in current user's .usr file
* @param array $values
*
*/
function rcUserSaveValues($values){
// Save only if single user profile
if($_SESSION['user']['accountType']!='singleUser' && !$_SESSION['user']['administrator']) return;
$needSave=false;
// Load original user data
$users=cfMGetVar('weezoUsers');
$userConfig=$users[$_SESSION['user']['id']];
// Apply new entries
foreach ($values as $key=>$value) if(!isset($userConfig[$key]) || $userConfig[$key]!=$value){
$userConfig[$key]=$value;
$modified=true;
}
// Commit to file and inform app
if(isset($modified)) rcWriteUserFile($userConfig, basename($_SESSION['user']['configFilename']));
}
/**
* @desc Get main info on type/subtype resource
*
* @param string $type
* @param string $subType
* @return array (type,subType,iconFile,describer)
*/
function rcGetResourceDefinition($type, $subType){
$res=cfMGetVar('weezoResourceDefinition'.strtolower($type).strtolower($subType));
$res['name']=rcResourceCaptionUTF8($type,$subType,$res);
$res['description']=rcResourceDescriptionUTF8($type,$subType,$res);
return $res;
}
/**
* @desc Add a resource to one or more users
*
* @param string $rid: resoure id OR resource config filename
* @param mixed $uids: 'all', user id or array of users ids
*/
function rcResourceAddToUsers($rid,$uids){
// If $rid is resource config filename, find resource id
if(strpos($rid,'.res')){
foreach (cfMGetVar('weezoResourcesList') as $k=>$v) if($v==$rid){
$rid=$k;
$rFilename=$v;
break;
}
if(!isset($rFilename)) return false;
}
// Get resource config filename from rid (as filename is resource identifier in user description)
elseif(!($rFilename=cfArrayItem(cfMGetVar('weezoResourcesList'),$rid))) return false;
// Get resource definition
$rd=cfMGetVar('weezoResData'.$rid);
$updated=0;
// Browse users to find concerned user
if(!is_array($uids) && $uids!=='all') $uids=array($uids);
foreach ($users=cfMGetVar('weezoUsers') as $uid=>$user) if($uids=='all' || @$_POST['user']===$uid || in_array($uid,$uids)) {
$max=-1;
$alreadyBound=0;
// Count resources to append at end, and check this user doesn't already have this resource
foreach ($user as $k=>$v) if(cfCmpLeft($k,'resource') && isset($v['file'])){
// If resource already bound to user, exit
if($v['file']==$rFilename) {
$alreadyBound=1;
break;
}
$max=max($max,substr($k,8)); // $k="resourceX"
}
if($alreadyBound) continue;
// Add resource to user
$user['resource'.($max+1)]=array('type'=>$rd['type'],'subType'=>$rd['subType'],'file'=>$rFilename);
rcWriteUserFile($user);
$updated++;
}
// If at least one user updated, rebind users / resources in memory
if($updated){
require_once(INCLUDE_DIR.'initFunctions.php');
ifResetResourcesUsers();
}
}
/*
***************************************************************************************************************************
* Misc actions
***************************************************************************************************************************
*/
/**
* @desc Unlink all thumbnails of current resource
* @return int: number of deleted files
*
*/
function rcThumbnailsClear($path=false){
if(!$path){
global $resourceData;
global $fileName;
$path=cfAppDataDir()."/res/".$resourceData['type'] ."/".$resourceData['subType']."/". cfFileWithoutExtension($fileName);
}
$nb=0;
// Clear subdir's thumbnails
foreach (glob($path.'/*',GLOB_ONLYDIR) as $completeFilename) $nb+=rcThumbnailsClear($completeFilename);
// Unlink empty directories
foreach (glob($path.'/*',GLOB_ONLYDIR) as $completeFilename) @rmdir($completeFilename);
// Clear current dir's thumbnails
foreach (glob($path.'/*.jpg') as $completeFilename) {
@unlink($completeFilename);
$nb++;
}
// Return number of deleted files
return $nb;
}
/**
* @desc Delete resource file and inform application
*
* @param string $fileName
*/
function rcDeleteResource($fileName){
// Remove file
if(!file_exists(cfAppDataDir().'/'.$fileName)) return true;
@unlink(cfAppDataDir().'/'.$fileName);
// Remove from memory
$rl=cfMGetVar('weezoResourcesList');
foreach ($rl as $rid=>$rFileName) if($rFileName==$fileName){
@cfMUnsetVar('weezoResData'.$rid);
unset($rl[$rid]);
cfMSetVar('weezoResourcesList',$rl);
break;
}
// Inform app
cfServerSendCommand('deleteResource file="'.$fileName.'"');
// Reset users-resources associations
require_once(INCLUDE_DIR.'initFunctions.php');
ifResetResourcesUsers(false,false);
return true;
}
/**
* @return boolean : true if success, false if user file couldn't be deleted
* @param string $fileName : file name (not including path)
* @desc Delete .usr user configuration file, and inform application to remove user from list
*/
function rcDeleteUser($fileName){
// Delete file
@unlink(cfAppDataDir().'/'.$fileName);
// Inform application (which delete file (once again), update general.ini, and it's internal controls)
cfServerSendCommand('userDeleted file="'.$fileName.'"');
cfLog('administration : '.$fileName.' user file deleted by '.$_SERVER['REMOTE_ADDR'], LOG_DBG);
// Reload users into memory
require_once(INCLUDE_DIR.'initFunctions.php');
ifLoadUsers();
return true;
}
/*
***************************************************************************************************************************
* New resource form
***************************************************************************************************************************
*/
/**
* @desc Insert new resource popup and scripts
*
* @param array $allowed: array(type=>array(subtype1,subtype2,...), ...) of allowed new resource. If not set, all resources are allowed
* @param bool $standalone: true if form is displayed in standalone webbrowser (UI)
*/
function rcNewResourceForm($allowed=false,$standalone=false){
$resourcesDefinitions=cfMGetVar('weezoResourcesDefinitions');
$users=cfMGetVar('weezoUsers');
// Re-order explorer resources
$explOrder=array('Photo1','File1','music3','Video','multimedia','music1','music2','musicWinamp');
$expl=array(); foreach ($explOrder as $k) $expl[$k]=$resourcesDefinitions['explorer'][$k];
foreach ($resourcesDefinitions['explorer'] as $k=>$v) if(!isset($expl[$k])) $expl[$k]=$v;
$resourcesDefinitions['explorer']=$expl;
// Prepare resource tree
$tree=array('ico'=>outIcon('resources'),'path'=>'top','label'=>'','sub'=>array());
// For each types
foreach (array('explorer','administration','webcam','website','blog','bookmarks','tv','misc') as $typeName=>$type) if(isset($resourcesDefinitions[$type]) && (!$allowed || isset($allowed[$type]))){
// No administration config in remote admin
if($type=='administration' && !cfIsInApp()) continue;
// Init type's node
$tree['sub'][$type]=array(
'ico'=>'/res/'.$type.'/resourceIconSmall.'.((file_exists(cfAppDocRoot().'/res/'.$type.'/resourceIconSmall.png'))?'png':'gif'),
'label'=>'<b>'.cfCaption('res'.ucfirst($type)).'</b>',
'unfolded'=>true,
'sub'=>array());
$nbSub=0;
// Search type's resources
if(isset($resourcesDefinitions[$type])) foreach ($resourcesDefinitions[$type] as $subType=>$memVarName) {
// filter on displayed resources
if($allowed && !isset($allowed[$type][strtolower($subType)])) continue;
// remove deprecated
if(!($rData=rcGetResourceDefinition($type,$subType)) || isset($rData['deprecated']) || isset($rData['describer']['deprecated'])) continue;
// Single instance resource: Browse all resources to see if this resource has already been created
if(@$rData['describer']['singleInstance']) {
$found=0;
foreach (WEnv::resConfigs() as $id=>$resConfig) if($resConfig->definition('type')==$type && $resConfig->definition('subType')==$subType){
$found=1;
break 2;
}
if($found) continue;
}
// Set node
$tree['sub'][$type]['sub'][$subType]=array(
'ico'=>$rData['resourceIconSmall'],
'label'=>$rData['name'],
'sub'=>array()
);
$nbSub++;
if(!isset($firstSelected)){
$tree['sub'][$type]['sub'][$subType]['selected']=1;
$firstSelected=1;
}
// JS Array Data
$description[$type][$subType]=array($rData['name'],$rData['description'],$rData['resourcePreviewImage']);
}
// If no sub nodes, remove type-level node
if($nbSub==0) unset($tree['sub'][$type]);
}
// Create treeView
$popupTreeView=new treeView('popupResTree');
$popupTreeView->phpTree=$tree;
$popupTreeView->selectFunction='popupSelectRes';
$popupTreeView->dblClickFunction='popupSelectAndValidateRes';
// Create description JS array
$rd='';
foreach ($description as $type=>$stDesc){
$rd.=(($rd=='')?'{':',').'"'.$type.'":';
$st='';
foreach ($stDesc as $subType=>$desc){
$st.=(($st=='')?'{':',').'"'.$subType.'":';
$st.='Array("'.addslashes($desc[0]).'","'.addslashes($desc[1]).'","'.addslashes($desc[2]).'")';
}
$rd.=$st.'}';
}
$rd.='}';
?>
<script type="text/javascript">
var resourcesDefinitions=<?php echo $rd;?>;
var standalone=<?php echo (int)$standalone;?>;
var resConfig,newResUseFilesList=0,selectedNode;
function popupSelectRes(node){
var path=node.getPath().split('/');
if(path.length==2) {
node.toggleFold();
return;
}
node.setSelected();
selectedNode=node;
resConfig={'newResType':path[1],'newResSubType':path[2]};
var desc=resourcesDefinitions[path[1]][path[2]];
dgi('popupNewResDescTitle').innerHTML=desc[0];
dgi('popupNewResDescText').innerHTML=desc[1];
dgi('popupNewResDescImageDiv').innerHTML='<img id="resPreviewImg" style="width:266;height:200">';
var img=D.createElement('IMG'); img.src=desc[2]; //WA
dgi('resPreviewImg').src=desc[2]
wl.button.enable('step1Next');
}
function popupSelectAndValidateRes(node){
var path=node.getPath().split('/');
if(path.length==2) return;
resConfig={'newResType':path[1],'newResSubType':path[2]};
selectedNode=node;
step1Next();
}
function step1Next(noBack){
if(noBack) dgi('step1Prev').style.display='none';
var e,li=(new wl.blockItemGroup('userBI')).getItems();
for(e in li) {
if(resConfig['newResType']!='administration') li[e].enable();
else if(li[e].n.alt!="userAdminControl") li[e].enable(0);
}
dgi('stepLb').innerHTML=(noBack)?'':'(2/2)';
dgi('resourceName').value=selectedNode.getLabel()
dgi('step1Frame').style.display='none';
dgi('step2Frame').style.display='';
dgi('resourceName').select();
}
function step2Prev(){
dgi('stepLb').innerHTML='(1/2)';
dgi('step1Frame').style.display='';
dgi('step2Frame').style.display='none';
}
function popupValidate(){
// Add selected users
var i,u=D.getElementsByTagName('FIELDSET'),users='';
for(i=0;i<u.length;i++) if(u[i].getAttribute('name')=='userBI' && $(u[i]).e.className().has('biSel')) users+='/'+(u[i].id.substr(4));
if(users) wl.objectsAdd(resConfig,{'users':users.substr(1)});
wl.objectsAdd(resConfig,{'resourceName':dgi('resourceName').value});
if(newResUseFilesList) wl.objectsAdd(resConfig,{'useFilesList':1});
if(standalone) wl.UICommand('close:newResource:'+wl.arrayPack(resConfig))
else {wl.asr.send(resConfig);popupHide();}
}
// Show step1 frame of new resource popup
function newResPopupShow(shownNodes,useFilesList,inApp){
newResUseFilesList=useFilesList?1:0;
var n,typeNode,firstNode=0,ids,id,subType,tn,nbSubNodes=0;
for(typeNode in treeViews['popupResTree'].tree['sub']){
n=new treeNode('popupResTree_top/'+typeNode);
if(shownNodes && !shownNodes[typeNode]) {
n.hideNode();
}
else {
n.showNode();
if((shownNodes && typeof shownNodes[typeNode])=='object'){
ids=n.childrenNodesIds();
for(id in ids){
subType=id.toLowerCase();
if(!shownNodes[typeNode][subType]) {
tn=(new treeNode(ids[id]))
tn.hideNode()
}
else{
tn=(new treeNode(ids[id]))
tn.setSelected();
selectedNode=tn
if(!firstNode) firstNode=tn;
nbSubNodes++;
}
}
}
if(!firstNode) firstNode=n.firstChild()
}
}
var pn=dgi('popupNewRes');
maskShow(0,1);
pn.style.visibility="hidden";
pn.style.display="";
maskMoveAbove(pn);
pn.style.visibility="";
pn.style.height="405px"; //XXX
<?php if(!$standalone) echo '$(pn).e.center();';?>
// Single type/subtype: go to step2
if(nbSubNodes==1) {
popupSelectRes(firstNode)
step1Next(1);
}
else{
pn.focus()
D.onkeydown=popupKP;
popupSelectRes(firstNode)
}
}
function popupHide(){
if(standalone) wl.UICommand('close:')
maskHide(1);
dgi('popupNewRes').style.display="none";
D.onkeydown=null;
}
function popupKP(evt){if(!evt) evt=W.event;if(evt.keyCode==27) popupHide()}
</script>
<div id="popupNewRes" style="position:absolute;display:none">
<?php
if($standalone){
$class='frame1';
$classL='frame2';
$classR='frame1';
$subClassR='frame3';
}
else {
outShadowBefore('700px');
$class='popup';
$classL=$classR='frame1';
$subClass2='frame2';
}
?>
<div class="<?php echo $class;?>" style="padding:5px;width:690px">
<?php
echo '<div class="'.$class.'Header" style="font-size:150%">'.outImageIcon('new32').cfCaption('resNewResource').'<span id="stepLb" style="margin-left:2em">(1/2)</span></div>';
/**
* 1st Step (resource type selection) frame
*/
?>
<div id="step1Frame" style="height:389px;overflow:hidden;padding:0px;margin:0px">
<?php
echo outTableTransparent(false,'table-layout:fixed');
echo '<td style="width:220px" >';
// Resources tree
echo $popupTreeView->HTML($classL,false,false,'height:379px;margin-top:0px;margin-bottom:0px');
// Detail frame
?>
<td style="width:0.5em"></td><td style="position:relative;vertical-align:top">
<div class="<?php echo $classR;?>" style="margin-bottom:0.5em;margin-top:0px">
<div id="popupNewResDescTitle" style="font-weight:bold;margin:6px;margin-bottom:10px"> </div>
<center style="margin-top:5px;margin-bottom:5px">
<div id="popupNewResDescImageDiv">
<img alt="" src="/ext/image.php" style="width:266px;height:200px;margin:10px" onload="fade(this)">
</div>
<div class="<?php echo $subClassR;?>" id="popupNewResDescText" style="width:95%;text-align:justify;font-size:120% !important;font-size:80%;height:110px;overflow:auto"> </div>
</center>
</div>
<table style="width:100%;margin-top:5px"><tr>
<?php
// Cancel button
echo '<td>'.outButton(cfCaption('genCancel'),'javascript:popupHide()',outIcon('cancel'),false,false,'').'</td>';
// Next button
echo '<td style="text-align:right">'.outButton(cfCaption('explorerNext'),'javascript:step1Next()',outIcon('next'),false,'step1Next','',false,true).'</td>';
?>
</tr></table>
</td></table>
</div>
<?php
/**
* 2nd Step (resource name and groups selection) frame
*/
?>
<div id="step2Frame" style="height:389px;overflow:hidden;display:none;font-size:135%;padding-top:5px">
<b style="font-size:74%"><?php echo cfCaption('newResourceChooseName');?></b><br>
<input class="textInput" id="resourceName" style="width:80%;font-size:100%"><br>
<br>
<b style="font-size:74%"><?php echo cfCaption('newResourceSelectUsers');?></b><br>
<div class="<?php echo $classL;?>" style="height:225px;overflow:auto;font-size:100%" id="usersFrame">
<?php
// Display users list
foreach ($users as $id=>$user) if(!@$user['invisible']){
$out='<div style="float:left;margin-right:1em;padding:0px"><img src="'.cfExtGFX('/gfx/icons/'.$user['icon'],40,40).'" style="width:40px;height:40px;visibility:hidden" onload="fade(this)"></div>';
$out.=cfUTF8Encode($user['name']);
if(@$user['administrator']) $out.='<br><div class="warning smallFont">'.cfCaption('userAdministrator').'</div>';
echo outBlockItem('userBI',$out,'alt="'.((@$user['administrator'])?'userAdminControl':'').'" id="user'.$user['id'].'"','width:210px;min-width:200px;padding:5px;overflow:hidden;text-overflow:ellipsis;cursor:pointer',array('type'=>'checkbox'));
}
?>
</div>
<div class="extendedInfo" style="font-size:80%">
<?php echo outImageIcon('info2').cfCaption('newResourceMayChange'); ?>
</div>
<table style="width:100%;margin-top:10px"><tr>
<?php
// Back button
echo '<td>'.outButton(' '.cfCaption('explorerPrevious').' ','javascript:step2Prev()',outIcon('backRed'),false,'step1Prev').'</td>';
// Cancel button
echo '<td style="text-align:center">'.outButton(cfCaption('genCancel'),'javascript:step2Prev();popupHide()',outIcon('cancel'),false,false).'</td>';
// Create button
echo '<td style="text-align:right">'.outBt(cfCaption('adminResourceCreate'),outIcon('new'),'javascript:popupValidate()',false,false,'','up',100).'</td>';
?>
</tr></table>
</div>
</div>
<?php if(!$standalone) outShadowAfter(); ?>
</div>
<?php
}
/*
***************************************************************************************************************************
* HTML / JS Output
***************************************************************************************************************************
*/
/**
* @desc Insert Javascript function needed for save button activation, and <form> with hidden fields
* This function must be called before variables processing (rcProcessData)
*
*/
function rcInsertScriptAndForm(){
global $resourceData;
global $fileName;
$isAdvancedConfig=!isset($resourceData['resourceFilename']);
// Javascript
?>
<noscript>
<div class="frame2" ><b class="warning"><?php echo outImage(outIcon('alertBig.png'),false,false,'float:left').cfCaption('loginErrorNoJavascript');?></b><br/><br/><br/></div><br/>
</noscript>
<script language="javascript" type="text/javascript">
var buttonEnabled=0;
function eSaveBt(dataName,dataValue){
if(window[dataName+"_changed"]) if(window[dataName+"_changed"](dataValue)=='cancel') return;
if(dataName=='name' && parent && parent.resourceNameModified) parent.resourceNameModified(dgn('resourceConfigFilename',0).value, dataValue);
if(W.dataChanged) {
if(dataChanged(dataName,dataValue)===false){
wl.button.disable('saveButton');
wl.button.enable('cancelButton');
buttonEnabled=1;
return;
}
}
if(!buttonEnabled){
wl.button.enable('cancelButton');
wl.button.enable('saveButton');
buttonEnabled=1;
}
<?php if(cfIsInApp()) echo 'save(1)';?>
}
function dataChangedNV(dataName){
var item=dgn(dataName);
if(!item) return;
if(item.type=='checkbox') dataValue=item.checked;
else if(item.type=='radio') {
var items=document.getElementsByName(dataName)
for(var i=0;i<items.length;i++) if(items[i].checked) dataValue=items[i].value;
}
else dataValue=item.value;
if(W.dataChanged) dataChanged(dataName,dataValue);
}
function toggleAdvancedConfig(id,state){
dgi('cancelButton').className+=''; // IE WA
if(state=='doneUnfold'){
dgi('advancedConfigOuter').className='advancedConfigUnfolded';
dgi('advancedConfigUnfoldBt').style.display='none';
dgi('advancedConfigFoldBt').style.display='';
dgn("advancedConfig").checked=true;
save(1);
}
if(state=='doneFold'){
dgi('advancedConfigOuter').className='advancedConfigFolded';
dgi('advancedConfigUnfoldBt').style.display='';
dgi('advancedConfigFoldBt').style.display='none';
dgn("advancedConfig").checked=false;
save(1);
}
}
// Save / apply changes
function save(async,fromBt){
<?php if(!$_ENV['buttonLessConfig']) echo 'if(!fromBt) return;';?>
if(async) asyncSubmitForm('configForm');
else{
for(e in dgn('configForm').getElementsByTagName('input')) {e=dgn('configForm').getElementsByTagName('input')[e] ;if(e.disabled) e.disabled=false};
for(e in dgn('configForm').getElementsByTagName('select')) {e=dgn('configForm').getElementsByTagName('select')[e] ;if(e.disabled) e.disabled=false};
document.configForm.submit()
}
}
<?php
/**
* User-configuration-only scripts (no advanced config)
*/
if(!$isAdvancedConfig){
?>
// Bind user context menu
function createUnboundUsersCM(unboundUsers){
var items=new Array(),i=0,e;
for(e in unboundUsers){
items[i]=ContextMenuItem(unboundUsers[e]["icon"],unboundUsers[e]["name"],"bindUser('"+e+"')");
i++;
}
ContextMenuAttach(dgi('showUnboundUsersBt'),items,{'align':'right','leftClick':1,'button':1,'style':{'width':130}})
}
// Bind user to resource (in app only)
function bindUser(uid){
parent.toggleUser("<?php echo $resourceData['resourceFilename'];?>",uid);
}
// Unbind user from resource (in app only)
function unbindUser(uid){
parent.toggleUser("<?php echo $resourceData['resourceFilename'];?>",uid);
}
// Show users panel and select user
function UIShowUser(uid){wl.UICommand('showUser:'+uid)}
<?php } ?>
</script>
<?php
// Insert
if(cfIsInApp() && !$isAdvancedConfig) echo '<div style="width:473px">';
// cancel form
echo '<form action="'.$_SERVER['PHP_SELF'].'" method="GET" enctype="multipart/form-data" name="cancelForm" style="display:none">';
if(!cfIsInApp()) echo '<input type="hidden" name="config" value="'.$fileName.'">';
if(cfIsInApp()) echo '<input type="hidden" name="resourceConfigFilename" value="'.$fileName.'">';
echo '<input type="hidden" name="cancel" value="true">';
echo '</form>';
// Submit changes form
echo '<form id="configForm" name="configForm" action="'.$_SERVER['PHP_SELF'].'" method="POST" enctype="multipart/form-data" style="padding:0;margin:0">';
if(!cfIsInApp()) echo '<input type="hidden" name="config" value="'.$fileName.'">';
if(cfIsInApp()) echo '<input type="hidden" name="resourceConfigFilename" value="'.$fileName.'">';
echo '<input type="hidden" name="commandSent" value="modify">';
if(isset($_SESSION['activeResourceId'])) echo '<input type="hidden" name="resId" value="'.$_SESSION['activeResourceId'].'">';
}
/**
* @desc Insert resource icon and name in configuration form
*
* @param array $resourceData
*/
function rcInsertIconName(&$resourceData){
global $limitedConfig;
$resourceDefinition=cfMGetVar('weezoResourceDefinition'.strtolower($resourceData['type'].$resourceData['subType']));
// In application: show delete button, resource icon, resource modifiable name and resource type label
if(cfIsInApp()){
echo outButton(cfCaption('genDelete'),"javascript:parent.deleteResource('".$resourceData['resourceFilename']."')",outIcon('del'),false,false,'style="float:right"');
echo outImage($resourceDefinition['resourceIcon'],false,false,'vertical-align:bottom;float:left;margin-right:1em');
echo '<div style="margin-top:5px">';
rcProcessData('name',dataText,$resourceData['name'],array(1,50),array('<span class="bigFont">'.cfCaption('resName').'</span>',36),false);
echo '</div>';
echo '<br>';
}
// Limited configuration
elseif ($limitedConfig){
echo '<div class="frame1Header">';
echo outImage($resourceDefinition['resourceIconSmall'],false,'','vertical-align:middle;margin-right:1em');
echo cfUTF8Encode($resourceData['name']);
echo '</div>';
return ;
}
// Remote administration
else{
echo outImage($resourceDefinition['resourceIcon'],false,'','vertical-align:middle;margin-right:1em');
rcProcessData('name',dataText,$resourceData['name'],array(1,50),cfCaption('resName'));
}
$users=rcResourceGetUsers($resourceData['resourceFilename']);
$allUsers=cfMGetVar('weezoUsers');
echo '<div id="resourceUsersList" style="margin-bottom:10px">';
// Generate linked users list
$list='';
foreach ($users as $id=>$user) {
if(cfIsInApp()) {
$list.=', <span style="text-decoration:underline" class="link" onclick="UIShowUser(\''.$user['id'].'\')">'.str_replace('<','<',str_replace('>','>',cfUTF8Encode($user['name']))).'</span>';
$list.='(<img src="'.outIcon('cancelVSNarrow').'" style="cursor:hand;vertical-align:middle" onclick="javascript:unbindUser(\''.$id.'\')" title="'.str_replace('"',"''",cfCaption('genRemove')).'">)';
}
else{
$list.=', <span>'.cfUTF8Encode($user['name']).'</span>';
}
}
if($list) {
$out='<div class="extendedInfo">';
$out.='<span style="width:80%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">';
$out.=outImageIcon('info2').'<b>'.cfCaption('resSharedWith').cfCaption('genSeparator').'</b>'.substr($list,1);
}
else {
$out='<div class="extendedWarning">';
$out.='<span style="width:80%;overflow:hidden;text-overflow:ellipsis;white-space:nowrap">'.outImageIcon('warning').cfCaption('resSharedWithNone');
}
$out.='</span>'; // End of overflow hidden
// List unbound users (in-app only)
$unbound='';
if(cfIsInApp() && count($users)<count($allUsers)) foreach ($allUsers as $id=>$user) {
// if not already bound, and not "system" user
if(!isset($users[$id]) && !@$user['invisible'] &&
// and not admin resource or user is admin
($resourceData['type']!=='administration' || @$user['administrator'])){
$unbound.=',"'.$user['id'].'":{"name":"'.str_replace('"','"',cfUTF8Encode($user['name'])).'","icon":"'.(cfExtGFX('/gfx/icons/'.$user['icon'],16,16)).'"}';
}
}
// Bind new user control (in-app only)
if($unbound){
$out.='<span class="link" style="position:absolute;right:5px" id="showUnboundUsersBt">'.cfCaption('genAdd').outImage(outIcon('down'),false,false,'vertical-align:bottom"').'</span>';
$unbound='createUnboundUsersCM(unboundUsers={'.substr($unbound,1).'});';
}
$out.='</div>'; // end of extendedInfo/warning
// Async response (in-app only, as in remote admin, output is buffered using ob_XXX and injected into a div
if(cfIsAsync() && cfIsInApp()) {
rcAddAsyncResponse(cfAsyncXMLInnerHTMLbyId($out,'resourceUsersList'));
if($unbound) rcAddAsyncResponse(cfAsyncXMLJSaction($unbound));
}
// Sync display
else {
echo $out;
if($unbound) echo '<script type="text/javascript">'.$unbound.'</script>';
}
echo '</div>';
}
/**
* @desc Included into config script of resources requiring MySQL: if MySQL not installed, echo error message and return false
*
* @return boolean: false if MySQL not installed, true if installed
*/
function rcMySQLCheckInstalled(){
if(cfMySQLInstalled()) return true;
echo '<br><br><div class="extendedWarning"><br>';
echo outImage(outIcon('warning'),false,false,'float:left');
echo '<center>'.cfCaption('extMySQLRequired').'<br><br>';
echo outButton(cfCaption('resMisc').'...',"javascript:wl.UICommand('pluginmanagement')",outIcon('plugins'));
echo '</center> </div>';
return false;
}
/**
* @desc Insert Folder / files list selection sub-form
*
* @param array $fileTypeFilter: array of mime types included, false for no filter
* @param string $defaultDirectory: default shared directory, false to use cfAppSharedDir()
* @param array $options:
* 'noDiv'=>1 : do not include outer div
* 'noSubDir'=>1 : do not include sub directories
*/
function rcSharedFilesBox($fileTypeFilter=false, $defaultDirectory=false, $options=false){
global $limitedConfig;
global $resourceData;
if($limitedConfig) return;
// Filter (audio/video/image)
if($fileTypeFilter) {
$fileTypeFilter=cfArrayValuesToKeys($fileTypeFilter);
require_once(INCLUDE_DIR.'mime_type.php');
foreach ($fileTypeFilter as $ftf){
foreach ($_ENV['weezoMime'] as $ext=>$mime) if(cfCmpLeft($mime,$ftf)) $extFilterArray[$ext]=$ext;
}
$extFilter='*.'.implode(';*.',$extFilterArray);
}
else $extFilter='';
// Backward compatibility: set sharedMode to folder for previously created resources
if(!isset($resourceData['sharedMode'])) {if(isset($resourceData['path'])) $resourceData['sharedMode']='folder'; else $resourceData['sharedMode']='list';}
if(!isset($options['noDiv'])) echo outDivFrame('frame2');
/**
* Share mode selection
*/
echo '<div class="frame2Header">'.outTableTransparent('frame2Header').'<tr><td>';
echo cfCaption('genFiles').cfCaption('genSeparator').'</td><td>';
rcProcessData('sharedMode',dataList,'list',array('folder','list'),array(
array(false,'folder',array(outIcon('folder'),cfCaption('sharedFolder').'</td><td>')),
array(false,'list',array(outIcon('filesList'),cfCaption('sharedFilesList')))
));
echo '</td></tr></table></div>';
/**
* Shared Folder
*/
echo '<div class="frame3" id="sharedModeFolder"'.(($resourceData['sharedMode']==='list')?' style="display:none"':'').'>';
// Base folder
rcProcessData('path',dataFolderPath,(($defaultDirectory)?$defaultDirectory:cfAppSharedDir()),((isset($options['noComputerRoot']))?'noComputerRoot':false),true);
// Subdirectories included
if(!isset($options['noSubDir'])) rcProcessData('subFoldersIncluded',dataBoolean,true,false,cfCaption('explorerCfgSubDirectoriesIncluded'));
echo '</div>';
/**
* List of files/folders
*/
echo '<div id="sharedModeList"'.(($resourceData['sharedMode']==='folder')?' style="display:none"':'').'>';
// shared items, | separated
if(!isset($resourceData['sharedItems'])) $resourceData['sharedItems']=false;
if($resourceData['sharedMode']=='folder') $_POST['sharedItems']=$resourceData['sharedItems']; // Prevent list modification if sharedMode is folder
// Hidden control containing items list, | separated
echo '<div style="position:absolute;top:-1000px">'; rcProcessData('sharedItems',dataText,'',false,' '); echo '</div>';
if($resourceData['sharedMode']=='list'){
require_once(INCLUDE_DIR.'explorerFunctions.php');
$out=''; $str='';$dir=array();$file=array();
// Generate HTML list from string
foreach (explode('|',$resourceData['sharedItems']) as $cfn){
if(cfFileExtension($cfn)=='lnk') $cfn=cfShortcutResolve($cfn);
if(is_dir($cfn)) $dir[$cfn]=efIcon($cfn);
elseif(file_exists($cfn)) {
// Apply filter (images, audio, video)
if($fileTypeFilter && !isset($fileTypeFilter[efFileType($cfn)])) continue;
$file[$cfn]=efIcon($cfn);
}
}
// list item html
function li($cfn,$ico){
static $nb=0;
if(!$cfn) return '<div class="'.((($nb++)%2)?'odd':'even').'"> </div>';
if(!cfIsInApp()) return '<div class="'.((($nb++)%2)?'odd':'even').'" id="'.cfUTF8Encode($cfn).'">'.outImage($ico,false,'class="ico2"').'<span onmouseover="tmp=lTt(this);tooltip(this,tmp)">'.cfUTF8Encode(basename($cfn)).'</span><br clear="all"></div>';
return '<div class="'.((($nb++)%2)?'odd':'even').'" id="'.cfUTF8Encode($cfn).'">'.outButtonSmall(false,'javascript:filesRemove(this)',outIcon('eraser'),cfCaption('genRemove'),false,'style="float:right"').outImage($ico,false,'class="ico2"').'<span onmouseover="tooltip(this,lTt(this))">'.cfUTF8Encode(basename($cfn)).'</span><br clear="all"></div>';
}
$nb=0;
// Add dirs
foreach ($dir as $cfn=>$ico) {
$out.=li($cfn,$ico);
$str.='|'.$cfn;
$nb++;
}
// Add files
foreach ($file as $cfn=>$ico) {
$out.=li($cfn,$ico);
$str.='|'.$cfn;
$nb++;
}
while($nb++<7) $out.=li(false,false);
$resourceData['sharedItems']=substr($str,1);
}
// Shared files & folders (drag & drop) box
echo '<div class="frame3 lvDiv" id="sharedItemsDropBox" style="position:relative;height:160px;overflow:auto;display:block">';
// files & folder list
if(isset($out)){
if(cfIsAsync() && cfIsInApp()) {
rcAddAsyncResponse(cfAsyncXMLInnerHTMLbyId($out.'<center style="position:absolute;top:0;width:100%;padding-left:15%;padding-right:15%;padding-top:55px" class="watermark">'.cfCaption('dropFilesHere').'</center>','sharedItemsDropBox'));
//rcAddAsyncResponse(cfAsyncXMLJSaction('scrollBottom();'));
}
else echo $out;
}
if(cfIsInApp()) echo '<center style="position:absolute;width:100%;top:0;padding-left:15%;padding-right:15%;padding-top:55px" class="watermark">'.cfCaption('dropFilesHere').'</center>';
echo '</div>';
// Drag & Drop and files&folders input box management
echo '<input name="dropFileInput" style="display:none" onkeyup="filesDropped()"><input type="button" name="dropFileButton" onclick="filesDropped()" style="display:none">';
// Add & clear all buttons (only in application UI)
if(cfIsInApp()){
// Add files & folders button
echo '<table style="width:100%"><tr><td>';
echo outButton(cfCaption('addFiles'),"javascript:wl.UICommand('openFiles:".$extFilter."','dropFileInput')",outIcon('addMult'),false,false);
// Clear all files button
echo '</td><td style="text-align:right">'.outButton(cfCaption('explorerClearAll'),'javascript:filesClearList()',outIcon('eraser'),false,false).'</td></tr></table>';
}
echo '</div>'; // #sharedModeList
?>
<script type="text/javascript">
var sharedMode="<?php echo $resourceData['sharedMode'];?>";
var extFilter=<?php if($extFilterArray) echo '{"'.implode('":1,"',$extFilterArray).'":1}'; else echo 'false'; ?>;
function scrollBottom(){dgi("sharedItemsDropBox").scrollTop=dgi("sharedItemsDropBox").scrollHeight}
function basename(cfn){
if(cfn.lastIndexOf('/')==cfn.length-1) cfn=cfn.substr(0,cfn.length-1);
return cfn.substr(cfn.lastIndexOf('/')+1);
}
function sharedMode_changed(val){
if(val=='folder') {
dgi('sharedModeList').style.display='none';
dgi('sharedModeFolder').style.display=''
D.getElementsByName('sharedMode')[1].checked=false //WA
}
else {
dgi('sharedModeFolder').style.display='none';
dgi('sharedModeList').style.display=''
D.getElementsByName('sharedMode')[0].checked=false //WA
}
sharedMode=val;
//IE bug WA
if(dgi("advancedConfigDiv")) {
with(dgi("advancedConfigDiv").style){overflow=(overflow=='hidden')?'':'hidden'; overflow=(overflow=='hidden')?'':'hidden';}
}
}
function filesDropped(){
var items=dgn('dropFileInput').value;dgn('dropFileInput').value='';
if(dgi('sharedModeList').style.display!='none') filesAdd(items);
}
function filesClearList(){
<?php
if(!cfIsInApp()) echo 'dgi("sharedItemsDropBox").innerHTML="";';
else{
?>
dgi('sharedItemsDropBox').innerHTML='<center style="position:absolute;width:100%;top:0;padding-left:15%;padding-right:15%;padding-top:75px" class="watermark"><?php echo cfCaption('dropFilesHere');?></center>';
<?php
}
?>
fillEmpty();
dgn('sharedItems').value='';
if(W.save) save(1);
if(W.rcSharedFilesBoxUpdated) rcSharedFilesBoxUpdated('');
}
function filesAdd(str){
if(!str) return;
var items=str.replace(/\\/g,'/').split('|');
var prevItems=dgn('sharedItems').value;
if(!prevItems) prevItems=new Array(); else prevItems=prevItems.split('|');
var pIL={}, output='',ext;
for(var i=0;i<prevItems.length;i++) pIL[basename(prevItems[i])]=prevItems[i];
for(var i=0;i<items.length;i++) {
if(!pIL[basename(items[i])]) {
if(extFilter){
ext=items[i].substr(items[i].lastIndexOf('.')+1).toLowerCase();
// if dir or allowed extension, add
if(items[i].lastIndexOf('.')<=items[i].lastIndexOf('/') || extFilter[ext]) pIL[basename(items[i])]=items[i];
}
else pIL[basename(items[i])]=items[i];
}
}
items=''; for(var e in pIL) items+='|'+pIL[e]; dgn('sharedItems').value=items.substr(1);
scrollBottom();
if(W.save) save(1); else filesOfflineUpdate(pIL)
if(W.rcSharedFilesBoxUpdated) rcSharedFilesBoxUpdated(dgn('sharedItems').value);
}
var filesRemoveTO=0;
function filesRemove(n){
if(filesRemoveTO) clearTimeout(filesRemoveTO); filesRemoveTO=0;
n=n.parentNode; cfn=n.id;
var n2=n.nextSibling;
n.parentNode.removeChild(n);
while(n2){
if(n2.className=='odd') n2.className='even';
else if(n2.className=='even') n2.className='odd';
else break;
n2=n2.nextSibling;
}
var items='',prevItems=dgn('sharedItems').value;
if(!prevItems) prevItems=new Array(); else prevItems=prevItems.split('|');
for(var i=0;i<prevItems.length;i++) if(prevItems[i]!=cfn) items+='|'+prevItems[i];
dgn('sharedItems').value=items.substr(1);
filesRemoveTO=setTimeout("save(1)",1500);
fillEmpty();
if(W.rcSharedFilesBoxUpdated) rcSharedFilesBoxUpdated(dgn('sharedItems').value);
}
function fillEmpty(){
var n=dgi("sharedItemsDropBox").firstChild;
var nb=0;
while(1){
if(n.className=='odd'||n.className=='even') nb++;
if(!(n=n.nextSibling)) break;
}
var out='';
while(nb++<8) out+='<div class="'+((nb%2)?'even':'odd')+'"> </div>';
html=dgi("sharedItemsDropBox").innerHTML;
var p=html.toLowerCase().indexOf('<center');
dgi("sharedItemsDropBox").innerHTML=html.substr(0,p)+out+html.substr(p);
}
function lTt(n){return '<span style="white-space:nowrap">'+n.parentNode.id+'</span>'}
function filesOfflineUpdate(items){
var item,o='',nb=0;
var WM=dgi("sharedItemsDropBox").innerHTML;
WM=WM.substr(WM.indexOf('<CENTER'));
for(var i in items){
item=items[i];
o+='<div class="'+((nb%2)?'odd':'even')+'">'+item+'</div>';
nb++;
}
while(nb<8) {
o+='<div class="'+((nb%2)?'odd':'even')+'"> </div>';
nb++;
}
dgi("sharedItemsDropBox").innerHTML=o+WM;
}
</script>
<?php
if(!isset($options['noDiv'])) echo '</div>';
}
/**
* @desc Insert HTML stuff for start of advanced configuration (folded or unfolded depending on $resourceData['advancedConfig'] value)
*
*/
function rcAdvancedConfigStart(){
global $resourceData;
global $limitedConfig;
$_ENV['advancedConfig']=1;
// Backward compatibility : set advanced as default for already configured resources
if(!isset($resourceData['advancedConfig'])){
if(isset($resourceData['resourceConfigured'])) $resourceData['advancedConfig']=true; else $resourceData['advancedConfig']=false;
}
echo '<span style="display:none">';
rcProcessData('advancedConfig',dataBoolean,false,false,'lc',false);
echo '</span>';
if(!$limitedConfig && $resourceData['advancedConfig']==false) $folded=true; else $folded=false;
echo outDivFrame("advancedConfig".(($folded)?'Folded':'Unfolded'),'id="advancedConfigOuter"');
echo '<div class="advancedConfigToggleBt" id="advancedConfigUnfoldBt" onclick="wl.nodeCollapseToggle(\'advancedConfigDiv\',false,\'toggleAdvancedConfig\')" '.(($folded)?'':'style="display:none"').'>'.cfCaption('configAdvanced').outimage(outIcon('advancedConfigFold'),false,false,'vertical-align:middle').'</div>';
echo '<div class="advancedConfigToggleBt" id="advancedConfigFoldBt" onclick="wl.nodeCollapseToggle(\'advancedConfigDiv\',false,\'toggleAdvancedConfig\')" '.(($folded)?'style="display:none"':'').'>'.cfCaption('configAdvanced').outimage(outIcon('advancedConfigUnfold'),false,false,'vertical-align:middle').'</div>';
echo outCollapsableFrame('advancedConfigDiv',false,false,$folded);
}
/**
* @desc Close advanced config divs
*
*/
function rcAdvancedConfigEnd(){
if(!isset($_ENV['advancedConfig'])) return ;
unset($_ENV['advancedConfig']);
echo "</div></div>\n";
}
/**
* @desc Insert configuration buttons to plugin's administration page, for use in application config tab
*
* @param string $path: path from resource root dir to config script
*/
function rcPluginConfigurationButtons($path){
global $resourceData;
if(!cfIsInApp()) return;
if($path[0]!='/') $path='/'.$path;
$extraPath=((strpos($path,'?')===false)?'?':'&').'weezoKey='.$_SESSION['weezoKey'];
// Resource administration button
echo '<div style="position:absolute;top:50%;left:0;width:99%;text-align:center">';
echo outButton(cfCaption('genConfigure'),'/res/'.$resourceData['type'].'/'.$resourceData['subType'].$path,outIcon('gears'));
echo ' ';
echo outButton(cfCaption('genConfigure').' ('.cfCaption('musicPopupPlayer').')','/res/'.$resourceData['type'].'/'.$resourceData['subType'].$path.$extraPath,outIcon('separateWindow'),false,false,' target="_blank"');
echo '</div>';
}
/**
* @return string : HTML code
* @desc return HTML code for theme selection, and theme preview link.
* Must be inserted in resource parameters form, returned (POST...) value is named 'theme'
*/
function rcThemeSelectionControl($theme=false){
global $resourceData;
// No possible selection for single-theme browsers
if(cfBGetVar('theme')) return;
$dir=cfAppDocRoot().'/themes';
if(!$theme){
// Default value
if(!isset($resourceData['theme'])) $resourceData['theme']='noTheme';
// Process POST command
if(isset($_POST['theme'])) $resourceData['theme']=cfUTF8Decode($_POST['theme']);
// Set Theme
$defaultTheme=$resourceData['theme'];
}
else $defaultTheme=$theme;
// Display control
$output = '<span style="margin-right:1em;">'.cfCaption('genTheme').'</span>';
$output .= '<select class="textInput" name="theme" id="themeSelect" size="1" style="width:15em;margin-right:1em;" '.(($theme)?'':'onChange="eSaveBt(\'theme\',this.value)"').'>';
// Display "no theme" item (only if $theme parameter is not set)
if(!$theme){
if($defaultTheme!='noTheme') $output .= '<option value="noTheme">'.cfCaption('adminNoTheme').'</option>';
else $output .= '<option selected value="noTheme">'.cfCaption('adminNoTheme').'</option>';
}
// Create themes select items
$themes=cfMGetVar('weezoThemes');
foreach ($themes as $name=>$data) if($name!='skins/default' && !isset($data['private'])){
if($name==$defaultTheme) $output .= '<option selected value="'.cfUTF8Encode($name).'">'.cfUTF8Encode($name).'</option>'; else $output .= '<option value="'.cfUTF8Encode($name).'">'.cfUTF8Encode($name).'</option>';
}
$output .= '</select>';
//$output .= outButton(cfCaption('genPreview'),'javascript:window.open(\'/themes/themePreview.php?theme=\' + document.getElementById(\'themeSelect\').value,\'Window\',\'width=600,height=460\');generateError;',outIcon('preview'));
return $output;
}
/**
* output a save and a cancel buttons dedicated to config.php scripts
*
* @return string : HTML code
* @param boolean $defaultCancelEnabled : set to true to enable cancel button, false to set it as disabled at page load
*/
function rcButtonSaveCancel($defaultCancelEnabled=false){
global $limitedConfig;
//Close advanced config divs
if(isset($_ENV['advancedConfig'])) echo "</div></div>\n";
$output='<center style="margin-top:0.3em'.(($_ENV['buttonLessConfig'])?';display:none':'').'">';
// Save/apply button
if((!cfIsInApp()) && basename($_SERVER['PHP_SELF'])=='index.php') $applyScript='save(1,1)'; // Remote configuration environment
// Limited configuration environment or application environment
// note: re-enable all input and select items in order to transmit them on form submition
else $applyScript='save(0,1)';
// Save/commit button
$output.=outButtonDisabled(cfCaption('genSave'),'javascript:'.$applyScript,outIcon('save'),false,'saveButton','style="margin-right:5em"');
// Browser environment: cancel close window (limited config) or reload page (remote administration)
if(!cfIsInApp())
$output .= outButton(cfCaption('genCancel'),(($limitedConfig)?'javascript:if(winMe) winMe.closeMe(); else window.close()':'javascript:reloadForm.submit()'),outIcon('cancel'),false,'cancelButton');
// App: use cancelForm to reset page
else {
$output.=outButton(cfCaption('genCancel'),'javascript:D.cancelForm.submit();',outIcon('cancel'),false,'cancelButton',false,false,!$defaultCancelEnabled);
}
$output .= '</center></form>';
if(!cfIsAsync()) echo cfDragRegisterItems('');
return $output;
}
/**
* @desc Load data required for "limited configuration" (ie inline configuration by end-user), and display page's head and script
*
*/
function rcInitLimitedConfig(){
global $resourceData;
// Load current resource data into $resourceData used by config scripts
$resourceData=cfRGetVar();
$_ENV['buttonLessConfig']=false;
// Insert page's head
$_ENV['winCloseURL']='/res/'.cfRGetVar('type').'/'.cfRGetVar('subType').'/'.cfRGetVar('baseFile'); // Frameless close URL
cfInsertHEAD(false);
if(cfBGetVar('name')=='iPhone') echo '<meta name="viewport" content="width=device-width, user-scalable=1">';
?>
<script type="text/javascript">
function applyChanges(){
if(parent.win(winMe.getOpenerId())) parent.win(winMe.getOpenerId()).reload();
winMe.closeMe();
}
function keydown(e){
if(e && e.which==27) winMe.closeMe();
else if(window.event && window.event.keyCode==27) winMe.closeMe();
}
document.onkeydown=keydown;
</script>
<body onload="onLoadFunc()">
<?php
echo cfScriptLink('wz_dragdrop.js');
echo outDivFrame('frame1','id="limitedConfigFrame"',cfGetBrowser()=='ie'?'width:99%':'');
}
/**
* @desc Return HTML code for a resource (config) item
*
* @param string $rid: id of resource
* @param WUserConfig $uc: bound user config, if set, display all controls, else just display selectable resource
* @return string
*/
function rcResourceBlock($rid,$uc=false){
$r=cfMGetVar('weezoResData'.$rid);
$o='';
// Icon
$o.=outImage($r['definition']['resourceIcon'],false,false,'float:left;margin-right:0.5em');
// Name
$o.='<div class="uiUsersResTitle">'.cfUTF8Encode($r['name']).'</div>';
$o.='<div class="uiUsersResL2">'.cfUTF8Encode(@$r['definition']['resourceTypeLabel']).'</div>';
$o.='<div class="uiUsersResL3">';
$st=$r['subType'];
switch ($r['type']){
case 'explorer':
if(@$r['sharedMode']=='folder') $o.=cfUTF8Encode($r['path']);
elseif(@$r['sharedMode']=='list') $o.=cfCaption('sharedFilesList');
break;
case 'bookmarks':
if($st=='std' ||$st=='mosaic'){
if(@$r['bookmarksType']=='Opera') $o.='Opera';
elseif(@$r['bookmarksType']=='Firefox') $o.='Firefox';
elseif(@$r['bookmarksType']=='IE') $o.='Internet Explorer';
else $o.=cfCaption('bookmarksCustom');
}
break;
case 'website':
if($st=='external') $o.=cfRGetVar('url');
if($st=='html') $o.=cfUTF8Encode(basename(cfRGetVar('path')));
break;
}
$o.='</div>';
// UI users tab: include controls
if($uc){
$nb=count($uc->getResources());
$i=0;
$pos=0;
foreach ($uc->getResources() as $id=>$res){
if($id==$rid) $pos=$i;
$i++;
}
// Resource actually displayed at login page
if($uc->getVar('displayResourceAtLogin')==$rid) $o.='<div style="position:absolute;left:3px;top:3px" '.outToolTip('<span style=\'text-decoration:line-through\'>'.cfCaption('userUseMainpage').'</span>').' onclick="uiUsersResLogin()">'.outImage(outIcon('sel'),false,'onmouseover="this.src=\''.outIcon('selCancel').'\'" onmouseout="this.src=\''.outIcon('sel').'\'"').'</div>';
// Remove control
$o.=outImage(outIcon('cancelVS12'),'javascript:uiUsersResDel(\''.$rid.'\')',outToolTip(cfCaption('genRemove')), 'position:absolute;right:3px;top:3px');
// Set as displayed at login page
if($uc->getVar('displayResourceAtLogin')!=$rid) $o.=outImage(outIcon('selectedVS'),'javascript:uiUsersResLogin(\''.$rid.'\')',outToolTip(cfCaption('userUseMainpage')), 'position:absolute;right:3px;bottom:3px');
// Up
if($pos>0) $o.=outImage(outIcon('up'),'javascript:uiUsersResUp(\''.$rid.'\')',outToolTip(cfCaption('genUp')), 'position:absolute;left:8px;top:26px');
// Down
if($pos<$nb-1) $o.=outImage(outIcon('down'),'javascript:uiUsersResDown(\''.$rid.'\')',outToolTip(cfCaption('genDown')), 'position:absolute;left:20px;top:26px');
// a single res may be selected
$opt=array();
// ondblclick function: configure resource
$onclick=" ondblclick=\"wl.UICommand('showResource:".$rid."')\"";
}
else {
// Multiple res may be selected
$opt=array('type'=>'checkbox');
// onclick function
$onclick=' onmousedown="toggleRes(\''.$rid.'\')" ondblclick="selectRes(\''.$rid.'\')"';
}
return outBlockItem('uiUsers',$o,'id="uiUsersResBlock_'.$rid.'"'.$onclick,'padding:5px;width:170px;text-align:left;margin:2px;margin-right:0px;margin-left:4px',$opt);
}
/*
***************************************************************************************************************************
* Main parameter processing / display
***************************************************************************************************************************
*/
/**
* @desc insert an image and / or a caption depending on $controlDefinitionArray definition
*
* @param array $controlDefinitionArray
* $controlDefinitionArray is a one or two elements array of image or caption definition (icd)
* (if $controlDefinitionArray is a string then it is treated as a one-element array)
* - if icd is false, don't display anything
* - if documentRoot/icd or resource's directory/icd is an image, display this image
* - else display icd as a caption
*
* @param alignLabelControl or alignControlLabel $align : defines wether control is located right or left of caption/image
* use this parameter to insert right or left margins
* @return unknown
*/
function rcDisplayLabelAndOrImage($controlDefinitionArray,$align){
global $resourceData;
if($align==alignLabelControl) $alignStyle="margin-right:0.3em;"; else $alignStyle="margin-left:0.3em;";
$alignStyle.='cursor:pointer;vertical-align:middle';
// Check $controlDefinitionArray format
if(!is_array($controlDefinitionArray)) {$item1=$controlDefinitionArray;$item2=false;}
elseif (count($controlDefinitionArray)==1) {list($item1)=$controlDefinitionArray;$item2=false;}
elseif (count($controlDefinitionArray)==2) {list($item1,$item2)=$controlDefinitionArray;}
else return false;
if($item1){
// Check if item1 is an image
if(is_file(cfAppDocRoot().$item1)) echo outImage($item1,false,false,$alignStyle);
elseif(isset($resourceData['type']) && isset($resourceData['subType']) && file_exists(cfAppDocRoot().'/res/'.$resourceData['type'].'/'.$resourceData['subType'].'/'.$item1)) echo outImage('/res/'.$resourceData['type'].'/'.$resourceData['subType'].'/'.$item1, false, $alignStyle);
// Else item1 is a caption
else echo '<span style="'.$alignStyle.'">'.$item1.'</span>';
}
if($item2){
// Check if item2 is an image
if(file_exists(cfAppDocRoot().$item2)) echo '<img alt="" style="'.$alignStyle.'" src="'.$item2.'">';
elseif(isset($resourceData['type']) && file_exists(cfAppDocRoot().'/res/'.$resourceData['type'].'/'.$resourceData['subType'].'/'.$item2)) echo '<img alt="" style="'.$alignStyle.'" src="/res/'.$resourceData['type'].'/'.$resourceData['subType'].'/'.$item2.'">';
// Else item2 is a caption
else echo '<span style="'.$alignStyle.'">'.$item2.'</span>';
}
// Insert spacing after caption/image if needed
echo "\n";
if($align==alignControlLabel && ($item1 || $item2)){
$item1=strtolower($item1);
$item2=strtolower($item2);
if(($item1 && (substr($item1,-4)=='<br>' || substr($item1,-5)=='<br/>'))) return true;
if(($item2 && (substr($item2,-4)=='<br>' || substr($item2,-5)=='<br/>'))) return true;
echo " \n";
}
return true;
}
/**
* @desc process a resource parameter :
* - set default value
* - modify value if POST parameter received
* - display control for user input
*
* @param string $dataName : name of data
* @param integer $dataType : type of data :
* - dataText : text data
* - dataNumeric : numeric data
* - dataList : fixed list of data
* - dataBoolean boolean
* - dataFolderPath : path to folder
* - dataFilePath : path to file
*
* @param mixed $defaultValue : default value of data
* @param mixed $constraints : authorized values for data (see below). No constraint if set to false
* @param mixed $controlDefinition : user control definition (caption, icons,... see below). Control is not displayed if set to false
* @return boolean : true if OK, false if function parameters are not correct
*/
function rcProcessData($dataName, $dataType, $defaultValue, $constraints, $controlDefinition=false,$lineBreak=true, $sensitiveData=false){
global $resourceData;
global $modifiedValuePHPFunction;
global $resourceNameModified;
// Memorize previous data value
if(isset($resourceData[$dataName])) $previousValue=$resourceData[$dataName];
/*
***************************************************************************************************************************
* SET DEFAULT VALUE
***************************************************************************************************************************
*/
if(!isset($resourceData[$dataName])) $resourceData[$dataName]=$defaultValue;
/*
***************************************************************************************************************************
* PROCESS POST COMMANDS
***************************************************************************************************************************
*/
// correct POST value for booleans
if($dataType==dataBoolean && $controlDefinition && isset($_POST['commandSent']) && !isset($_POST[$dataName])) $_POST[$dataName]=false;
// Set new value if passed
if(isset($_POST[$dataName]) && $controlDefinition!==false) {
$requestedValue=cfUTF8Decode($_POST[$dataName],true,false,false);
switch($dataType){
// Text data
case dataText:
if($dataName=='name') $previousName=$resourceData['name'];
if(is_array($constraints) && count($constraints)==2){
list($nbMin,$nbMax)=$constraints;
if(($nbMin===false || strlen($requestedValue)>=$nbMin) && ($nbMax===false || strlen($requestedValue)<=$nbMax)) $resourceData[$dataName]=$requestedValue;
}
elseif (!$constraints) $resourceData[$dataName]=$requestedValue;
if($dataName=='name' && $previousName!=$resourceData['name']) $resourceNameModified=true;
break;
// Password
case dataPassword:
if($requestedValue && $requestedValue!=='weezoFakePassword') $resourceData[$dataName]=cfStoredPasswordCrypt($requestedValue);
break;
// Numeric data
case dataNumeric:
if(is_numeric($requestedValue) && is_array($constraints) && count($constraints)==2){
list($nbMin,$nbMax)=$constraints;
if(($nbMin===false || $requestedValue>=$nbMin) && ($nbMax===false || $requestedValue<=$nbMax)) $resourceData[$dataName]=$requestedValue;
}
elseif (is_numeric($requestedValue) && !$constraints) $resourceData[$dataName]=$requestedValue;
break;
// List
case dataList:
if(is_array($constraints) && in_array($requestedValue,$constraints)) $resourceData[$dataName]=$requestedValue;
break;
// Boolean data
case dataBoolean:
if($requestedValue=='true' || $requestedValue=='on') $resourceData[$dataName]=true;
else $resourceData[$dataName]=false;
break;
// File or folder path
case dataFolderPath:
case dataFilePath:
$requestedValue=str_replace('\\\\','/',$requestedValue);
if(substr($requestedValue,-1)=='/') $requestedValue=substr($requestedValue,0,strlen($requestedValue)-1);
if($dataType==dataFolderPath){
if(is_dir($requestedValue)) $resourceData[$dataName]=$requestedValue;
elseif($_POST[$dataName]==cfCaption('explorerComputerRoot') && $constraints!='noComputerRoot') $resourceData[$dataName]='computerRoot';
elseif (cfIsAsync()) rcAddAsyncResponse(cfAsyncXMLJSaction('dgn("'.$dataName.'").style.color="red"'));
}
elseif ($dataType==dataFilePath){
if(is_file($requestedValue)) $resourceData[$dataName]=$requestedValue;
elseif (cfIsAsync()) rcAddAsyncResponse(cfAsyncXMLJSaction('dgn("'.$dataName.'").style.color="red"'));
}
if(cfIsSubDir(cfAppDataRootDir(),$resourceData[$dataName])) $resourceData[$dataName]='*appDir*'.substr($resourceData[$dataName],strlen(cfAppDataRootDir()));
break;
}
}
/*
***************************************************************************************************************************
* DISPLAY CONTROL
***************************************************************************************************************************
*/
if($controlDefinition){
if($sensitiveData) echo '<span class="warning">';
switch($dataType){
// TEXT OR NUMERIC DATA
// Control definition :
// array(input lenght, $controlDefinitionArray) : text input (size=input lenght) with image and/or caption
// array($controlDefinitionArray,input lenght) : image and/or caption with text input (size=input lenght)
// array($controlDefinitionArray,input lenght, $controlDefinitionArray) : image and/or caption with text input (size=input lenght) and image and/or caption
case dataText:
case dataNumeric:
$inputType='text';
case dataPassword:
if(!isset($inputType)) {
$inputType='password';
$inputValue=(cfStoredPasswordDecrypt($resourceData[$dataName]))?'weezoFakePassword':'';
}
else $inputValue=str_replace('"','"',cfUTF8Encode($resourceData[$dataName]));
if(!is_array($controlDefinition)) $controlDefinition=array($controlDefinition,45); // default control : set size at 45
if(count($controlDefinition)==2){
list($item1,$item2)=$controlDefinition;
// Textbox - caption
if(is_numeric($item1)){
echo '<input onKeyUp="eSaveBt(\''.$dataName.'\',this.value)" onChange="eSaveBt(\''.$dataName.'\',this.value)" type="'.$inputType.'" class="textInput" name="'.$dataName.'" size="'.$item1.'" value="'.$inputValue.'">';
rcDisplayLabelAndOrImage($item2,alignControlLabel);
}
// Caption - Textbox
elseif (is_numeric($item2)){
rcDisplayLabelAndOrImage($item1,alignLabelControl);
echo '<input onKeyUp="eSaveBt(\''.$dataName.'\',this.value)" onChange="eSaveBt(\''.$dataName.'\',this.value)" type="'.$inputType.'" class="textInput" name="'.$dataName.'" size="'.$item2.'" value="'.$inputValue.'">';
}
}
// Caption - Textbox - Caption
elseif (count($controlDefinition)==3 && is_numeric($controlDefinition[1])){
list($item1,$item2,$item3)=$controlDefinition;
rcDisplayLabelAndOrImage($item1,alignLabelControl);
echo '<input onKeyUp="eSaveBt(\''.$dataName.'\',this.value)" onChange="eSaveBt(\''.$dataName.'\',this.value)" type="'.$inputType.'" class="textInput" name="'.$dataName.'" size="'.$item2.'" value="'.$inputValue.'">';
rcDisplayLabelAndOrImage($item3,alignControlLabel);
}
break;
// VALUES LIST : 2 types of controls : <select> droplist or radio buttons
// Control definition :
// <select> :
// array($controlDefinitionArray, array of items, $controlDefinitionArray)
// items : array(value, caption)
// Radio buttons:
// array of items
// items : array(left-side $controlDefinitionArray, value, right-side $controlDefinitionArray)
case dataList:
if(!is_array($controlDefinition) || count($controlDefinition)<2) return false;
if($resourceData[$dataName]===true) $resourceData[$dataName]='true';
if($resourceData[$dataName]===false) $resourceData[$dataName]='false';
//<select>
if(count($controlDefinition)==3 && is_array($controlDefinition[1]) && ((!is_array($controlDefinition[0])) || count($controlDefinition[0])<3)){
list($item1,$item2,$item3)=$controlDefinition;
rcDisplayLabelAndOrImage($item1,alignLabelControl);
echo '<select name="'.$dataName.'" size="1" class="textInput" onChange="eSaveBt(\''.$dataName.'\',this.value)">';
foreach ($item2 as $value) {if(is_array($value) && count($value)==2) echo '<option value="'.$value[0].'"'.(($resourceData[$dataName]==$value[0])?' selected':'').'>'.$value[1]."</option>\n";}
echo "</select>\n";
rcDisplayLabelAndOrImage($item3,alignControlLabel);
}
else{
// Radio buttons
$radioNb=0;
foreach ($controlDefinition as $value){
if(is_array($value) && count($value)==3){
list($item1,$item2,$item3)=$value;
if($item1) {echo '<span style="cursor:pointer" onclick="dgn(\''.$dataName.'\','.$radioNb.').checked=\'checked\';dgn(\''.$dataName.'\','.$radioNb.').click()">'; rcDisplayLabelAndOrImage($item1,alignControlLabel); echo '</span>';}
else rcDisplayLabelAndOrImage($item1,alignControlLabel);
//rcDisplayLabelAndOrImage($item1,alignLabelControl);
echo '<input type="radio" name="'.$dataName.'" style="cursor:pointer;vertical-align:middle" onClick="eSaveBt(\''.$dataName.'\',this.value)" value="'.$item2.'" '.(($resourceData[$dataName]==$item2)?'checked="checked"':'').">\n";
if($item3) {echo '<span style="cursor:pointer" onclick="dgn(\''.$dataName.'\','.$radioNb.').checked=\'checked\';dgn(\''.$dataName.'\','.$radioNb.').click()">'; rcDisplayLabelAndOrImage($item3,alignControlLabel); echo '</span>';}
else rcDisplayLabelAndOrImage($item3,alignControlLabel);
$radioNb++;
}
}
}
break;
// BOOLEAN DATA
case dataBoolean:
// Checkbox
// Control definition :
// array($controlDefinitionArray) : checkbox with image and/or caption
// array($controlDefinitionArray,$controlDefinitionArray) : 2 radio buttons with image and/or caption
if(!is_array($controlDefinition)) $controlDefinition=array($controlDefinition);
// Checkbox
if(count($controlDefinition)==1){
echo '<input type="checkbox" onChange="eSaveBt(\''.$dataName.'\',this.checked)" onClick="eSaveBt(\''.$dataName.'\',this.checked)" name="'.$dataName.'" '.(($resourceData[$dataName])?'checked':'').' style="vertical-align:middle"/>';
echo '<span onclick="obj=dgn(\''.$dataName.'\');if(obj.disabled) return; obj.checked=!obj.checked;eSaveBt(\''.$dataName.'\',obj.checked);">';
rcDisplayLabelAndOrImage($controlDefinition[0],alignControlLabel);
echo '</span>';
}
// Radio button (Warning : first item is always true, second is always false)
elseif(count($controlDefinition)==2){
$first=true;
foreach ($controlDefinition as $value){
// radio button
// "true" button
if($first) echo '<input onChange="eSaveBt(\''.$dataName.'\',this.value)" onClick="eSaveBt(\''.$dataName.'\',this.value)" type = "radio" name="'.$dataName.'" value="true" '.(($resourceData[$dataName])?'checked':'').' style="vertical-align:middle">';
// "false" button
else echo '<input onChange="eSaveBt(\''.$dataName.'\',!this.value)" onClick="eSaveBt(\''.$dataName.'\',!this.value)" type = "radio" name="'.$dataName.'" value="false" '.((!$resourceData[$dataName])?'checked':'').' style="vertical-align:middle">';
// Image or label
echo '<span onclick="obj=document.getElementsByName(\''.$dataName.'\')['.(($first)?'0':'1').'];if(obj.disabled) return;obj.checked=true;eSaveBt(\''.$dataName.'\','.(($first)?'!':'').'this.checked);">';
rcDisplayLabelAndOrImage($value,alignControlLabel);
echo '</span>';
if($first) $first=false;
}
}
break;
// FILE OR DIRECTORY
// Control definition :
// optional string : caption
case dataFolderPath:
case dataFilePath:
// Corrects file/path case
$path=cfCorrectFilenameCase(str_replace('*appDir*',cfAppDataRootDir(),$resourceData[$dataName]),true);
if(cfIsSubDir(cfAppDataRootDir(),$path)) $resourceData[$dataName]='*appDir*'.substr($path,strlen(cfAppDataRootDir())); else $resourceData[$dataName]=$path;
if(is_array($controlDefinition)||substr($controlDefinition,0,4)!='<img') echo '<img alt="" src="'.(($dataType==dataFolderPath)?outIcon('folder'):outIcon('blankFile')).'" style="vertical-align:middle; margin-right:0.5em;">';
// Caption
if($controlDefinition!==true && !is_array($controlDefinition)) echo $controlDefinition;
elseif($dataType==dataFolderPath) echo '<b>'.cfCaption('genDirectory').'</b>';
else echo cfCaption('genFile');
// Input text box
echo '<input class="textInput" onKeyUp="eSaveBt(\''.$dataName.'\',this.value);this.style.color=\'\';" onchange="eSaveBt(\''.$dataName.'\',this.value);" type="text" name="'.$dataName.'" id="'.$dataName.'" size="32" style="margin-left:1em;margin-right:1em;'.(($path!='computerRoot' && !file_exists($path))?'color:red;':'').'" value="'.(($path=='computerRoot')?cfCaption('explorerComputerRoot'):cfUTF8Encode($path)).'">';
if($dataType==dataFolderPath){
// Folder selection button (application environment only)
if(cfIsInApp())
echo outButton(cfCaption('genBrowse'),"javascript:wl.UICommand('openFolder','".$dataName."')",outIcon('fi/folder'),cfCaption("genDirectory"),false,'onclick="eSaveBt(\''.$dataName.'\',this.value)"');
// Computer root button
if($constraints!='noComputerRoot') echo outButton('','javascript:dgi(\''.$dataName.'\').value=\''.cfCaption('explorerComputerRoot').'\';eSaveBt(\''.$dataName.'\',this.value);', outIcon('computerRoot'),cfCaption("explorerComputerRoot"));
// Special : 'path' data is commonly used as base directory for explorer resources - show help button
if($dataName=='path') echo ' '.outHelpButton('helpPath');
}
else{
// File selection button (application environment only)
if(cfIsInApp())
echo outButton(cfCaption('genBrowse'),"javascript:wl.UICommand('openFile','".$dataName.";".$constraints."')",outIcon('explorer'),false,false,'onclick="eSaveBt(\''.$dataName.'\',this.value)"');
}
break;
}
if($sensitiveData) echo '</span>';
// Line break
if($lineBreak) echo "<br>\n";
}
// If a callback function has been set (rcSetModifiedValuePHPFunction) and data has changed,
// call callbackfunction with dataName and previousValue parameters
if(isset($modifiedValuePHPFunction)){
if(!isset($previousValue)) $modifiedValuePHPFunction($dataName,false);
elseif($previousValue!=$resourceData[$dataName]) $modifiedValuePHPFunction($dataName,$previousValue);
}
}
?>